package com.tianqu.tms.www.proxy.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.DateUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.Member;
import com.tianqu.tms.entity.TransferAcceptedInfo;
import com.tianqu.tms.www.proxy.controller.CarProxyInputResultController;
import com.tianqu.tms.www.proxy.viewhelper.CarProxyInputViewHelper;
/**
 * 
 * 进入待办受理录入结果页面Action
 * 
 * @author Administrator
 *
 */
public class CarProxyInputResultAction extends TmsAction {
	private Logger logger = Logger.getLogger(CarProxyInputResultAction.class);
		
	private static final String SYSPATH = "sysPath";
	
	private static final String LEFTLINE ="/";
	
	private static final String TMSPATH = "/tmsweb";
	
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");

		CarProxyInputViewHelper view = (CarProxyInputViewHelper)uc.getAttribute(TmsConstants.VIEWHELP);
		TransferAcceptedInfo accept = new TransferAcceptedInfo();
		accept = accept.findTransStatusBySerial(view.getSerial());
		if (accept != null) {
			if(accept.getMaterialImages1()!=null && !"".equals(accept.getMaterialImages1()))
			{
				view.setMaterialImages1(accept.getMaterialImages1());
				view.setMaterialImages2(accept.getMaterialImages2());
				view.setMaterialImages3(accept.getMaterialImages3());
				view.setMaterialImages4(accept.getMaterialImages4());
				view.setMaterialImages5(accept.getMaterialImages5());						
			}else{
				setErrorsToRequest(request, TmsConstants.IM007, null);
				return mapping.getInputForward();
			}
		} else {
			setErrorsToRequest(request, TmsConstants.IM007, null);
			return mapping.getInputForward();
		}
		isToken(mapping, request);
		CarProxyInputResultController controller = new CarProxyInputResultController();
		String sysPath = request.getSession().getServletContext().getRealPath(LEFTLINE).replace(TMSPATH, TmsConstants.BLANK);
		uc.setAttribute(SYSPATH, sysPath);
		controller.execute(uc);
		
		uc.removeAttribute(TmsConstants.VIEWHELP);
		
		view.setPrintBsflag("1");
		
		TransferAcceptedInfo accept1 = new TransferAcceptedInfo();
		
		accept1 = accept1.getAssessInfoBySerial(view.getSerial());
		String dbTime = DateUtil.getTimeByTimeStamp(accept1.getAgentTime());
		view.setAgentTime(dbTime);
		String dbrq = DateUtil.getDateByTimeStamp(accept1.getAgentTime());
		String jzrq = DateUtil.getAfterMonth1(2, dbrq);
		
		view.setAgentJZTime(jzrq);
		
		Member member = Member.getInstance();
		member = member.findMemberInfoByMemId(view.getMemberId());
		if(member!=null)
		{
			view.setLegal(member.getLegal());
			view.setPhone(member.getPhone());
		}else{
			view.setLegal("");
			view.setPhone("");			
		}
		view.setMemberName(member.getRealName());

		request.setAttribute(TmsConstants.VIEWHELP, view);
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
